local fubian = fk.CreateSkill{
  name = "wk_heg__fubian",
}

Fk:loadTranslationTable{
  ["wk_heg__fubian"] = "抚边",
  [":wk_heg__fubian"] = "与你势力不同的角色使用牌指定与你势力相同的角色为目标后，你可以交给其一张牌并与其同时展示一张手牌，若两牌颜色不同，此牌对所有与你势力相同的角色无效。",
  ["#wk_heg__fubian-invoke"] = "抚边：你可交给 %dest 一张牌",
  ["#wk_heg__fubian-show"] = "抚边：请展示一张牌",
}

local HG = require "packages/new_heg_diy_my/util"
local H = require "packages/ol_hegemony/util"

fubian:addEffect(fk.TargetSpecified, {
  anim_type = "defensive",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and H.compareKingdomWith(player, target, true) and not player:isNude() and data.firstTarget
      and table.find(data:getAllTargets(), function (p)
        return H.compareKingdomWith(player, p)
      end)
  end,
  on_cost = function (self, event, target, player, data)
    local cards = player.room:askToCards(player,{
      min_num = 1, 
      max_num = 1,
      skill_name = fubian.name,
      include_equip = true, 
      prompt = "#wk_heg__fubian-invoke::"..target.id})
    if #cards > 0  then
      event:setCostData(self, {tos = {target}, cards = cards})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cost_data = event:getCostData(self)
    room:obtainCard(target, cost_data.cards, false, fk.ReasonGive, player, fubian.name)
    if player:isKongcheng() or target:isKongcheng() then return end
    local jointtable = room:askToJointCards(player, { ---@type table<ServerPlayer, integer[]>
      players = {player,target}, 
      min_num = 1, 
      max_num = 1,
      include_equip = false, 
      skill_name = fubian.name, 
      cancelable = false, 
      prompt = "#wk_heg__fubian-show"})
    local nuil, color = false, nil
    for p, c in pairs(jointtable) do
      p:showCards(c)
      if color == nil then
        color = Fk:getCardById(c[1]).color
      else
        if color == Fk:getCardById(c[1]).color then
          nuil = true
        end
      end
    end
    if nuil then
      local targets = table.filter(room.alive_players, function (p)
        return H.compareKingdomWith(player, p)
      end)
      data.use.nullifiedTargets = data.use.nullifiedTargets or {}
      for _, p in ipairs(targets) do
        table.insertIfNeed(data.use.nullifiedTargets, p)
      end
    end
  end,
})

return fubian